<?php
/**
 * @package solaitra
 * @author $author$
 * @version $Id$
 */

 /**
 * module vetso
 * For tononkalo serasera
 */

if (!defined('BASEPATH')) exit('No direct script access allowed');

class Rss extends Controller {
	var $settings = array();
	function Rss()
	{
		parent::Controller();
		$this->template['module'] = "album";
		$this->load->model("album_model", "album");
		$this->load->helper('xml');
		//$this->load->helper("bbcode");
	}

	function index()
	{
		if($rows = $this->album->get_albums(array( 'order_by' => 'id DESC', 'limit' => 10)))
		{
			$data['encoding'] = 'utf-8';
			$data['feed_name'] = $this->system->site_name;
			$data['feed_url'] = base_url();
			$data['page_description'] = $this->system->meta_description;
			$data['page_language'] = $this->user->lang;
			$data['creator_email'] = (isset($this->system->admin_email))? $this->system->admin_email : "";
			
			
			foreach ($rows as $key => $row)
			{
				if ($row['o'])
				{
					$contents[$key]['title'] =  $row['title'];
					$contents[$key]['url'] = site_url('album/asehoy/' . $row['aid']);
					$contents[$key]['body'] = "<img src='" . $row['s'] . "' align='left'> " . $row['description'];
					$contents[$key]['date'] = (isset($row['date'])) ? $row['date'] : '';
					$contents[$key]['img'] = $row['o'];
					$contents[$key]['author'] = $row['username'];
					$contents[$key]['media'] = $row;
				}
			}
			$data['contents'] = $contents;
			header("Content-Type: application/xml");
			
			$this->load->view('rss', $data);
		}
	}
	
	
	function random()
	{
		if($rows = $this->album->get_albums(array( 'order_by' => 'RAND()', 'limit' => 10)))
		{
			$data['encoding'] = 'utf-8';
			$data['feed_name'] = $this->system->site_name;
			$data['feed_url'] = base_url();
			$data['page_description'] = $this->system->meta_description;
			$data['page_language'] = $this->user->lang;
			$data['creator_email'] = (isset($this->system->admin_email))? $this->system->admin_email : "";
			
			
			foreach ($rows as $key => $row)
			{
				$contents[$key]['title'] =  $row['title'];
				$contents[$key]['url'] = site_url('album/asehoy/' . $row['aid']);
				$contents[$key]['body'] = "<img src='" . $row['s'] . "' align='left'> " . $row['description'];
				$contents[$key]['date'] = (isset($row['date'])) ? $row['date'] : '';
				$contents[$key]['img'] = $row['o'];
				$contents[$key]['media'] = $row;
			}
			$data['contents'] = $contents;
			header("Content-Type: application/xml");
			
			$this->load->view('rss', $data);
		}
	}
	
	
}